<template>
	<view class="login-page">
		<image class="bc" src="../../static/image/bc.png" mode=""></image>
		<view class="login">
			<van-field name="手机号" label="手机号" placeholder="请填写手机号" @input="changePhone" />
			<van-field type="password" label="密码" placeholder="请输入密码" @input="changePassword" />
		</view>

		<van-button custom-class="login-btn" @click="login" block round>登录</van-button>
	</view>
</template>

<script>
	import {
		loginUser,
		modifyAccount
	} from '../../common/http/api.js'
	export default {
		data() {
			return {
				loginParams: {
					phone: '',
					password: ""
				}
			};
		},
		onLoad() {
			uni.setNavigationBarTitle({
				title: this.$store.state.cinemaName
			})
		},
		methods: {
			changePhone(e) {
				this.loginParams.phone = e.detail
			},
			changePassword(e) {
				this.loginParams.password = e.detail
			},
			login() {
				loginUser(this.loginParams).then(res => {
					if (res.code === "000") {

						uni.showToast({
							title: res.msg,
							icon: "none",
							duration: 1500
						})
						setTimeout(() => {
							uni.navigateTo({
								url: "../distributor/distributor?phone=" + this.loginParams.phone
							})
						}, 1500);
					} else if (res.code === "001") {
						uni.showToast({
							title: res.msg,
							icon: "none",
							duration: 1500
						})
					} else {
						uni.showToast({
							title: '登录失败',
							icon: "none",
							duration: 1500
						})
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	.login-page {
		.bc {
			position: absolute;
			width: 100vw;
			height: 100vh;
			z-index: -1;
			top: 0;
		}

		.login {
			width: 92vw;
			margin: 400rpx auto 0 auto;
			border-radius: 10rpx;
			overflow: hidden;
		}

		.login-btn {
			margin: 80rpx 4vw;
			width: 92vw;
			background-color: #007AFF;
			color: #fff;
			border: none;
		}
	}
</style>